<template>
	<view class="content">
		<view class="" v-if="list">
			<view class="box" v-for="(item,index) in time" :key="index">
				<view class="time">{{item}}</view>
				<view class="list" v-for="(i,t) in showList(item)" :key="t" @click="detaile(i)">
					<view class="listTitle">
						<view :class="['image',i.status==0?'news':'']"><!-- <image :src="i.coverJson" mode="" v-if="i.coverJson"></image> --></view>
						<view class="msg">
							<view class="msgTitle">{{i.title}}</view>
							<view class="msgMsg">{{i.content}}</view>
						</view>	
					</view>
					<view class="num">订单编号：{{i.number}}</view>
				</view>
			</view>
		</view>
		<view class="" v-if="list.length==0 || !list" style="padding-top:180rpx;">
			<image src="../../../static/none/news.png" mode="" class="none"></image>
			<view class="noneTxt">暂无消息</view>
		</view>
		<!-- 返回顶部 -->
		<back-top :scrollTop='scrollTop'></back-top>
	</view>
</template>

<script>
	import backTop from '../../../components/uni-ui/back-top/back-top.vue';
	import {selectMessageList,selectMsgInfo} from '@/apis/message/index.js'
	export default {
		data() {
			return {
				scrollTop:0,
				time:[],//时间列表
				list:'',//获取所有消息列表
			}
		},
		onLoad() {
		},
		onShow() {
			this.getList()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		computed:{
		//时间戳下的内容
		showList(item){
			return function(item){
				// console.log(item,'.....item')
				return this.list.filter(el=>el.createdAt.slice(0,10)==item)
			}
		}
		},
		components:{
			backTop,
		},
		methods: {
		async getList(){
				let res =await selectMessageList({messageType:0,nurseId:this.$store.state.userInfo.id})
				console.log(res,'订单消息返回')
				if(res.success){
					this.list=res.object
					let time = this.list.map(el=>el.createdAt.slice(0,10))
					this.time =Array.from(new Set(time)) 
					console.log(this.time[0],'订单是',time);
				}
			},
			async detaile(i){
				let res =await selectMsgInfo({id:i.id,messageType:0})
				console.log(i,'11')
				uni.navigateTo({
					url:'../../order/sub-order/sub-order?number='+i.number
				})
			},
			sliceTime(time){
				return time.slice(0,10)
			}
		}
	}
</script>

<style scoped lang="less">
	.content{
		// box-sizing:border-box;
		background:#FAFAFB;
		min-height:100vh;
	}
	.box{
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
		.time{
			height: 42rpx;
			background: rgba(0, 0, 0, 0.03);
			border-radius: 20rpx;
			line-height: 42rpx;
			display: inline-block;
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.38);
			padding: 0 24rpx;
			margin:16rpx auto ;
		}
		.list{
			width:100%;
			margin:16rpx 0;
			padding:42rpx 40rpx;
			box-sizing:border-box;
			background: #FFFFFF;
			.listTitle{
				display: flex;
				.image{
					width: 88rpx;
					height: 88rpx;
					border-radius: 20rpx;
					background: url(../../../static/img/news/orderMessage.png) ;
					background-size:88rpx 88rpx;
					image{
						// width:96rpx;
						// height:96rpx;
					}
				}
				.msg{
					margin-left: 24rpx;
					.msgTitle{
						height: 44rpx;
						font-size: 32rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #0E0E0E;
						line-height: 44rpx;
						margin-bottom: 16rpx;
						width:540rpx;
						overflow:hidden;
						
					}
					.msgMsg{
						width:540rpx;
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #8F8F8F;
						line-height: 40rpx;
						overflow:hidden;
					}
				}
			}
			.num{
				// width: 532rpx;
				height: 40rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #8F8F8F;
				line-height: 40rpx;
				text-align: right;
				margin-left: 178rpx;
				margin-top: 10rpx;
			}
		}
	}
	.none{
		width: 442rpx;
		height: 300rpx;
		display: block;
		margin: 0 auto;
		margin-bottom:80rpx;
		// padding-top:180rpx;
	}
	.noneTxt{
		font-weight: 500;
		font-size: 36rpx;
		color: #3E3E3E;
		// margin-top: 80rpx;
		text-align:center;
	}
	.news {
		position: relative;
		&:after {
			content: '';
			position: absolute;
			right:0;
			top: 0;
			display: block;
			width: 10rpx;
			height: 10rpx;
			background-color: #ff4f4f;
			border-radius: 50%;
		}
	}
</style>
